<?php

/**
 * This file is part of the Pagizer package.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @copyright   Copyright (c) 2010 Advisa (http://www.advisa.fr)
 * @author      Pagizer Core Team <team@pagizer.org>
 * @package     pagizer
 * @subpackage  users
 */

class m_users_actions_block_DeleteUserAction extends m_backoffice_extends_FormModal
{
	public function execute()
	{
		$superUser = $this->getDocumentProvider()->loadDocuments("modules_users/user")->retrieveFirstDocument();
		$user = f_document_Provider::getInstance()->getByModelAndUniqueId('users/User', $this->getRequestParameter("docId"));
		
		$disableDeletion = false;
		$messages = array();

		if($superUser->getUniqueId() == $user->getUniqueId())
		{
			$messages[] = "Vous ne pouvez pas supprimer le <strong>super utilisateur</strong>";
			$disableDeletion = true;
		}
		
		if($this->getUser()->getUniqueId() == $user->getUniqueId())
		{
			$messages[] = "Vous ne pouvez pas supprimer l'utilisateur courant";
			$disableDeletion = true; 
		}
				
		$this->addToModel("disableDeletion", $disableDeletion);
		$this->addToModel("messages", $messages);
		$this->addToModel("user", $user);

		$this->setView('success');
	}	
	
	public function validate()
	{
		return $this->getUserContext()->hasRight(array("backoffice_accessBo","users_Delete"));
	}
}